package edu.scau.core.Enum;

import io.swagger.v3.oas.annotations.media.Schema;

public enum SaleStatus {
    @Schema(name = "0", description = "创建中")
    created("创建中",0),
    @Schema(name = "1", description = "已创建")
    found("已创建",1),
    @Schema(name = "2", description = "已支付")
    paid("已支付",2),
    @Schema(name = "3", description = "已完成")
    completed("已完成",3);
    private final String desc;
    private final int signal;
    SaleStatus(String desc,int signal) {
        this.desc = desc;
        this.signal=signal;
    }

    public String getDesc() {
        return desc;
    }

    public int getSignal() {
        return signal;
    }
    //    public static ColorEnum fromString(String color) {
//        for (ColorEnum c : ColorEnum.values()) {
//            if (c.color.equalsIgnoreCase(color)) {
//                return c;
//            }
//        }
//        throw  new IllegalArgumentException("不存在该颜色选项");
//    }
    /**
     * 通过signal获取枚举常量
     * @param signal
     * @return
     */
    public static SaleStatus getBySignal(int signal) {
        for (SaleStatus status : SaleStatus.values()) {
            if (status.getSignal() == signal) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid signal: " + signal);
    }
}
